#import "CTSuperPlayerUtil.h"

NSString *kStrLoadFaildRetry = @"加载失败,点击重试";
NSString *kStrBadNetRetry = @"网络不给力,点击重试";
NSString *kStrTimeShiftFailed = @"时移失败，返回直播";
NSString *kStrHDSwitchFailed = @"清晰度切换失败";
NSString *kStrWeakNet = @"检测到你的网络较差，建议切换清晰度";

@implementation CTSuperPlayerUtil

+ (NSArray *)parseArrayValue:(id)value
{
    if (value && [value isKindOfClass:[NSArray class]]) {
        return value;
    }
    return @[];
}

+ (NSString *)parseStringValue:(id)value
{
    if (value) {
        if ([value isKindOfClass:[NSString class]]) {
            return value;
        } else if ([value isKindOfClass:[NSNumber class]]) {
            return [value stringValue];
        }
    }
    return @"";
}

+ (NSNumber *)parseNumberValue:(id)value
{
    if (value) {
        if ([value isKindOfClass:[NSNumber class]]) {
            return value;
        } else if ([value isKindOfClass:[NSString class]]) {
            return [NSNumber numberWithDouble:[value doubleValue]];
        }
    }
    return @(0);
}

+ (double)parseDoubleValue:(id)value {
    return [[self parseNumberValue:value] doubleValue];
}

+ (NSString *)formattedTime:(NSInteger)totalTime {
    if (totalTime < 0) {
        return @"";
    }

    NSInteger hour = totalTime / 3600;
    NSInteger minute = (totalTime / 60) % 60;
    NSInteger second = totalTime % 60;
    if (hour > 0) {
        return [NSString stringWithFormat:@"%zd:%02zd:%02zd", hour, minute, second];
    } else {
        return [NSString stringWithFormat:@"%02zd:%02zd", minute, second];
    }
}

@end
